package data.objects;


import java.util.Map;

import data.exceptions.Request_Parameter_Exception;

/**Klasse Request-Parameter die alle URL-Parameter in HashMaps abbildet
 * @author Markus
 *
 */
public class Request_Parameter {

	/**
	 * Quantity wird extra abgebildet, da int-Wert
	 */
	private int quantity=1;
	private Map<String,String> id_map;
	private Map<String,String> parameter_map;


	public Request_Parameter(){
		}

	
	public Map<String,String> getId_map() throws Request_Parameter_Exception {
//		if(id_map.isEmpty()){
//			throw new Request_Parameter_Exception("Keine id's vorhanden.");
//		}		
		return id_map;
		}
	public void setId_map(Map<String,String> id_map) {this.id_map = id_map;}
	
	public Map<String, String> getParameter_map() throws Request_Parameter_Exception {
		if(parameter_map.isEmpty()){
			throw new Request_Parameter_Exception("Keine Parameter vorhanden.");
		}
		return parameter_map;
		}
	public void setParameter_map(Map<String, String> parameter_map) {this.parameter_map = parameter_map;}
	
	public String getParameter(String key, Boolean optional) throws Request_Parameter_Exception{
		String result=parameter_map.get(key);
		if(result==null){
			if (optional) {
				result = "";
			}else{
				throw new Request_Parameter_Exception("Parameter "+key+" nicht vorhanden.");
			}
		}
		return result;
	}

	
	@Override
	public String toString() {
		return "Request_Parameter [id_map=" + id_map + ", parameter_map="
				+ parameter_map + "]";
	}

	
	public int getQuantity() {return quantity;}
	public void setQuantity(int quantity) {this.quantity = quantity;}

}
